<?php


namespace App\Models;


use App\System\traits\Paginatable;
use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\CustomerRecords
 *
 * @property int $id
 * @property int $user_id 用户ID
 * @property int $customer_id 客户ID
 * @property int $type 跟踪方式
 * @property int $result 跟踪结果
 * @property string $remark 跟踪详情
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|CustomerRecords newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|CustomerRecords newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|CustomerRecords query()
 * @method static \Illuminate\Database\Eloquent\Builder|CustomerRecords whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|CustomerRecords whereCustomerId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|CustomerRecords whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|CustomerRecords whereRemark($value)
 * @method static \Illuminate\Database\Eloquent\Builder|CustomerRecords whereResult($value)
 * @method static \Illuminate\Database\Eloquent\Builder|CustomerRecords whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|CustomerRecords whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|CustomerRecords whereUserId($value)
 * @mixin \Eloquent
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\CustomerRecordsFile[] $files
 * @property-read int|null $files_count
 * @property-read \App\Models\User $user
 */
class CustomerRecords extends Model
{
    use Paginatable;

    protected $table = 'customer_records';

    // 跟踪类型 电话
    const TYPE_MOBILE = 1;
    // 跟踪类型 见面
    const TYPE_MEET = 2;
    // 跟踪类型 其他
    const TYPE_OTHER = 3;

    // 跟踪结果 有意向
    const RESULT_INTENTION = 1;
    // 跟踪结果 成单
    const RESULT_ORDER = 2;
    // 跟踪结果 其他
    const RESULT_NORMAL = 3;

    public static $TYPES = [self::TYPE_MOBILE, self::TYPE_MEET, self::TYPE_OTHER];

    public static $RESULTS = [self::RESULT_INTENTION, self::RESULT_ORDER, self::RESULT_NORMAL];

    protected $fillable = ['user_id', 'customer_id', 'type', 'result', 'remark'];

    public function getTypeText()
    {
        switch ($this->type) {
            case self::TYPE_MOBILE:
                return '电话';
            case self::TYPE_MEET:
                return '见面';
            case self::TYPE_OTHER:
                return '其他';
        }
        return '';
    }

    public function getResultText()
    {
        switch ($this->result) {
            case self::RESULT_INTENTION:
                return '意向';
            case self::RESULT_ORDER:
                return '成单';
            case self::RESULT_NORMAL:
                return '其他';
        }
        return '';
    }

    public function files()
    {
        return $this->hasMany(CustomerRecordsFile::class, 'records_id');
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }

}
